package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.model.request.pc.PcEquipmentRequestBean;
import com.homedo.odin.solution.model.response.mng.MngEquipmentResponseBean;
import com.homedo.odin.solution.service.EquipmentListServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备清单报备接口
 *
 * @author chenlei
 * @date 2018/5/22
 */
@Api(description = "设备清单报备接口", tags = {"Equipment"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/equipment")
public class EquipmentController extends BaseController<EquipmentListServiceImpl> {

    @ApiOperation(value = "PC_设备清单报备", httpMethod = "POST", response = MngEquipmentResponseBean.class)
    @PostMapping()
    public ResultData getEquipments(@Valid @RequestBody PcEquipmentRequestBean requestBean,
            BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultData
                    .newInstance(new Meta(Meta.CODE_451.getCode(), bindingResult.getFieldError().getDefaultMessage()));
        }

        baseService.addEquipment(requestBean);

        return ResultData.newInstance();
    }
}
